<?php
/*
*	专题内容文章相关模型
*/
defined('BASEPATH') OR exit('No direct script access allowed');
class SpecialR_m extends MY_Model {
    public function __construct(){
        parent::__construct();
        $this->table='special_r';
    }
    //查询单条分类信息
    public function sel($where=array(),$field="*"){
        $this->com_where($where);
        $this->db->select($field);
        $query=$this->db->get($this->table);
        $data=$query->row_array();
        return $data;
    }
    //多条数据查询
    public function selall($where=array(),$field='*',$order='id desc'){
        $data = array();
        $this->com_where($where);
        $this->db->select($field);
        $this->db->order_by($order);
        $query = $this->db->get($this->table);
        $list = $query->result_array();
        return $list;
    }
    //批量插入数据文章 并更改写入文章数
    public function addmore($data){
        $this->db->trans_begin();
        $this->db->insert_batch($this->table, $data);
        $this->db->affected_rows();
        if(!$this->db->affected_rows()){
            $this->db->trans_rollback();return false;
        }
        //专题内容分类下文章数更改
        $CI = get_instance();
        $CI->load->model('specialContentType_m');
        if($CI->specialContentType_m->specialContent_rnum($data[0]['ctypeid'],1,count($data))===false){
            $this->db->trans_rollback();return false;
        }
        $this->db->trans_commit();
        return true;
    }
    //移除关联文章
    public function removemore($where,$data){
        $this->db->trans_begin();
        $this->com_where($where);
        $this->db->delete($this->table);
        if(!$this->db->affected_rows()){
            $this->db->trans_rollback();return false;
        }
         //专题内容分类下文章数更改
        $CI = get_instance();
        $CI->load->model('specialContentType_m');
        if($CI->specialContentType_m->specialContent_rnum($data['ctypeid'],2,$data['num'])===false){
            $this->db->trans_rollback();return false;
        }
        $this->db->trans_commit();
        return true;
    }
 }